home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / fileutil.13 / fileutil / fileutils-3.13 / src / dcgen.pl < prev    next >
Encoding:
Perl Script  |  1996-06-23  |  1.9 KB  |  72 lines

  1. #!@PERL@ -w
  2. # -*- perl -*-
  3. # @configure_input@
  4.  
  5. eval 'exec @PERL@ -S $0 ${1+"$@"}'
  6.     if 0;
  7.  
  8. # dcgen -- generate C declarations of arrays of lines and line lengths
  9. # Copyright (C) 1996 Free Software Foundation, Inc.
  10.  
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2, or (at your option)
  14. # any later version.
  15.  
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. # GNU General Public License for more details.
  20.  
  21. # You should have received a copy of the GNU General Public License
  22. # along with this program; if not, write to the Free Software
  23. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  24. # 02111-1307, USA.
  25.  
  26. # written by Jim Meyering
  27.  
  28. # If you uncomment the following lines, you should also do
  29. # s/chop/chomp and s/local/my/.
  30. #require 5.002;
  31. #use strict;
  32.  
  33. # Convert an arbitrary file to dcl of two arrays.
  34. # One of lines, the other of lengths.
  35.  
  36. local $prefix = 'G_';
  37.  
  38. local @line;
  39. while (<>)
  40.   {
  41.     chop;
  42.     push (@line, $_);
  43.   }
  44.  
  45. local $n = @line;
  46. print "#define ${prefix}N_LINES $n\n\n";
  47.  
  48. local $indent = '  ';
  49. print "const size_t ${prefix}line_length[${prefix}N_LINES] = \n{\n$indent";
  50. local $ind = $indent;
  51. local $i;
  52. for ($i = 0; $i < @line; $i++)
  53.   {
  54.     local $comma = ($i < @line - 1 ? ',' : '');
  55.     $ind = '' if $i == @line - 1;
  56.     local $sep = ($i && $i % 18 == 0 || $i == @line - 1 ? "\n$ind" : ' ');
  57.     print length ($line[$i]), $comma, $sep;
  58.   }
  59. print "};\n\n";
  60.  
  61. print "const char *const ${prefix}line[${prefix}N_LINES] =\n{\n";
  62. while (1)
  63.   {
  64.     $_ = shift (@line);
  65.     local $comma = (@line ? ',' : '');
  66.     print "$indent\"$_\"$comma\n";
  67.     last if !@line;
  68.   }
  69. print "};\n";
  70.  
  71. exit (0);
  72.